<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../../css/utils/bootstrap.min.css" />
    <link rel="stylesheet" href="../../css/utils/common.css" />
    <link rel="stylesheet" href="../../css/utils/toastr.min.css" />
	<title></title>
	<style>
		.table {
			margin-left: 1%;
			width: 98%;
		}
		/*-------------头部购买详情 次数------------*/
		.btn-tab {
			margin-top: 50px;
		}
		.input-btn-group {
			width: 382px;
			margin: 40px auto;
		}
		.input-btn-group input[type='text'] {
			float: left;
			width: 300px;
			border-top-right-radius: 0;
			border-bottom-right-radius: 0;
		}
		.input-btn-group .btn {
			background-color: #11B5AB;
			border-color: #11B5AB;
			color: #fff;
			border-top-left-radius: 0;
			border-bottom-left-radius: 0;
		}
		.input-btn-group .btn:focus, .input-btn-group .btn:hover {
			color: #fff;
			background-color: #2aeee2;
			border-color: #2aeee2;
		}
		.label-group .label {
			display: inline-block;
			padding: 3px 25px;
			margin-right: 20px;
			margin-bottom: 20px;
			background-color: #E1E1E1;
			color: #848484;
			cursor: pointer;
			border-top-left-radius: 10px;
			border-top-right-radius: 10px;
			border-bottom-left-radius: 10px;
			border-bottom-right-radius: 10px;
		}
		.label-group .label.active {
			background-color: #11B5AB;
			color: #fff;
		}
		/*-------------修改密码------------*/
		.col-top {
			margin-top: 100px;
		}
		.col-top .form-group {
			margin-bottom: 25px;
		}
		.text-red {
		    color: #ee4747;
		}
		.no-padder {
		    padding: 0 !important;
		}
		.btn-primary:focus, .btn-primary:hover {
			color: #fff;
			background-color: #2aeee2;
			border-color: #2aeee2;
		}
		.btn-primary {
		    color: #fff;
		    background-color: #11B5AB;
		    border-color: #11B5AB;
		}
		.cancle {
			color: #7B7B7B;
			background-color: #F3F3F3;
		    border-color: #F3F3F3;
		}
		/*-------------修改密码------------*/
		/*-------------公众号设置------------*/
		.col-align {
			text-align: center;
		}
		.btn-width {
			padding: 6px 50px;
		}
		#accountModify {
			display: none;
		}
		#payModify {
			display: none;
		}
		/*-------------公众号设置------------*/
		/*---------树----------*/
		.teams-content {
			margin-top: 40px;
			width: 100%;
			height: 745px;
			border: 1px solid #A1A1A1;
		}
		.uiwm-organset-left-header {
		    height: 45px;
		}
		.title-h4 {
			width:175px;
			text-overflow:ellipsis;
			overflow:hidden;
			height:20px;
			white-space:nowrap; 
			margin-top: 15px;
			margin-left: 15px;
		}
		.add-tree-parent {
			margin-top: 16px;
			margin-right: 20px;
			float: right;
            background: url(../../img/myCenter/add_icon.png) no-repeat;
            width: 14px;
            height: 14px;
            background-size: cover;
		}
		.client-details-container {
		    float: left;
			width: 20%;
	        border-color: #A1A1A1;
		    border-width: 0px 1px 0px 0px;
		    border-style: solid;
		}
		.client-details-container .list-group-item:first-child {
		    border-radius: 0px;
		}
		.client-details-container .list-group-item:last-child {
			border-radius: 0px;
		}
		.padder-xs {
		    margin-left: 5px;
		    margin-right: 5px;
		}
		/*.treeview .list-group-item span.click-add{
            display: inline-block;
            background: url(../../img/myCenter/add_icon.png) no-repeat;
            width: 14px;
            height: 14px;
            background-size: cover;
            margin-top: 3px;
        }*/
		.treeview .list-group-item span.click-edit{
            display: inline-block;
            background: url(../../img/myCenter/edit_icon.png) no-repeat;
            width: 14px;
            height: 14px;
            background-size: cover;
            margin-top: 3px;
        }
        .treeview .list-group-item span.click-remove{
            display: inline-block;
            background:url(../../img/myCenter/delete_icon.png) no-repeat;
            width: 14px;
            height: 14px;
            background-size: cover;
            margin-top: 3px;
        }
		/*---------树----------*/
		.table-pane {
			float: right;
			width: 80%;
		}
		.inline-panel {
			margin-left: 1%;
			margin-top: 30px;
			margin-bottom: 30px;
		}
		.form-inline .form-group-input {
			margin-left: 40px;
		    width: 40%;
			display: inline-block;
		    margin-bottom: 0;
		    vertical-align: middle;
		}
		.search-content {
			width: 100%;
		}
		.btn-add-employees {
			margin-right: 20px;
			color: #11B5AB;
			border-radius: 20px;
			border: 1px #11B5AB solid;
		}
		/*----------激活弹框-----------*/
		.QRCode-div {
			margin-left: 217px;
			width: 167px;
			height: 167px;
			background-image: url(../../img/myExtension/checkbox-false.png);
			background-size: 100% 100%;
		}
		.tips-pay {
			width: 640px;
			height: 700px;
		}
		.tips-align {
			text-align: center;
		}
		.tips-pay-div {
			font-size: 16px;
			color: #666666;
			font-family: "MicrosoftYaHei";
		}
		#pwdValidata {
			display: none;
		}
		/*----------激活弹框-----------*/
		/*----------标签编辑弹框-----------*/
		.uiwm-label-input {
		    margin: 40px auto;
		    width: 360px;
		    height: 40px;
		}
		.uiwm-label-input input {
		    border-radius: 0;
		    height: 40px;
		    width: 260px;
		    border-right: none;
		}
		.uiwm-label-input button {
		    width: 100px;
		    height: 40px;
		    background: #11B5AB;
		    border: none;
		    border-radius: 0;
		}
		/*----------标签编辑弹框-----------*/
		.rotate90 {
		    -webkit-transform: rotate(90deg);
		    -ms-transform: rotate(90deg);
		    transform: rotate(90deg);
		}
		.filter-box {
		    display: inline-block;
			position: relative;
		}
		.div-radius0  {
			border-top-left-radius: 16px;
			border-bottom-left-radius: 16px;
		}
		.div-radius1 {
			border-top-left-radius: 0px;
			border-bottom-left-radius: 0px;
		}
		.wechat-qrcode {
			height: 120px;
		}
		.wechat-qrcode label {
		    text-align: right;
    			margin-top: 40px;
		}
	</style>
</head>
<body>
	<div class="content">
		<div class="tab-content">
	  		<div class="teams-content">
				<div class="client-details-container">
					<div class="uiwm-organset-left-header">
                        <a href="#"><h4 class="pull-left title-h4" id="companyNameH4"></h4></a>
                        <span class="add-tree-parent"></span>
                    </div>
					<div id="treeview"></div>
				</div>
				<div class="table-pane">
					<div class="inline-panel">
						<div class="form-inline">
							<div class="filter-box">
								<select id="activationSt" class="form-control">
									<option value="">是否激活</option>
									<option value="1">已激活</option>
									<option value="0">未激活</option>
								</select>
							</div>
                            <div class="form-group-input">
                                <div class="search-content">
                            			<input id="searchInput" type="search" class="form-control" placeholder="输入员工姓名">
							   </div>
                            </div>
                            <a class="btn-add-employees pull-right btn" id="addEmployees">添加员工</a>
                        </div>
					</div>
			  		<table class="table table-bordered table-hover table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>姓名</th>
								<th>电话</th>
								<th>岗位</th>
								<th>邮箱</th>
								<th>激活状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="employeestbody">
						</tbody>
					</table>
					<nav id="employeesPage" class="text-center" aria-label="Page navigation">
						<ul class="pagination">
						</ul>
					</nav>
				</div>
			</div>
		</div>
	    <div class="modal fade" id="addDepartmentModal" tabindex="-1" role="dialog" aria-labelledby="addDepartmentModalLabel">
	        <div class="modal-dialog" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                    <h4 class="modal-title text-base" id="addDepartmentModalLabel">添加部门</h4>
	                </div>
	                <div class="modal-body">
	                    <form class="form-horizontal"  id="deptForm">
	                        <div class="form-group">
	                            <label for="recipient-name" class="control-label col-md-3">上级部门:</label>
	                            <div class="col-md-7 no-padder">
	                                <input type="text" class="form-control input-sm" readonly="readonly" id="parentDepartment">
	                                <input type="hidden" class="form-control input-sm" id="parentDepartmentId">
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-3">部门名称:</label>
	                            <div class="col-md-7 no-padder">
	                              <input type="text" class="form-control input-sm" id="department" maxlength="10"  placeholder="部门名称（最多10个字）"/>
	                              <input type="hidden" class="form-control input-sm" id="departmentId" />
	                            </div>
	                        </div>
	                    </form>
	                </div>
	                <div class="modal-footer">
	                    <button type="button" class="btn btn-default btn-sm padder-md" data-dismiss="modal">取消</button>
	                    <button type="button" class="btn btn-primary btn-sm padder-md" id="saveDeptBtn">保存</button>
	                </div>
	            </div>
	        </div>
	    </div>
	    <div class="modal fade" id="delDepartmentModal" tabindex="-1" role="dialog" aria-labelledby="delDepartmentModalLabel">
	        <div class="modal-dialog modal-sm" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                    <h4 class="modal-title text-base" id="delDepartmentModalLabel">提示</h4>
	                </div>
	                <div class="modal-body">
	                    <p class="text-black text-center"><i class="iconfont icon-wemai14 m-r-sm text-red"></i>您确定删除<span id="delDepartmentName"></span>吗？</p>
	                    <input type="hidden" name="delDepartmentId" id="delDepartmentId" value="">
	                </div>
	                <div class="modal-footer">
	                    <button type="button" class="btn btn-default btn-sm padder-md" data-dismiss="modal">取消</button>
	                    <button type="button" class="btn btn-danger btn-sm padder-md" id="delDeptBtn">删除</button>
	                </div>
	            </div>
	        </div>
	    </div>
	    <div class="modal fade" id="delEmployeesModal" tabindex="-1" role="dialog" aria-labelledby="delEmployeesModalLabel">
	        <div class="modal-dialog modal-sm" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                    <h4 class="modal-title text-base" id="delEmployeesModalLabel">提示</h4>
	                </div>
	                <div class="modal-body">
	                    <p class="text-black text-center"><i class="iconfont icon-wemai14 m-r-sm text-red"></i>您确定删除<span id="delEmployeesName"></span>吗？</p>
	                    <input type="hidden" name="delEmployeesId" id="delEmployeesId" value="">
	                </div>
	                <div class="modal-footer">
	                    <button type="button" class="btn btn-default btn-sm padder-md" data-dismiss="modal">取消</button>
	                    <button type="button" class="btn btn-danger btn-sm padder-md" id="delEmployBtn">删除</button>
	                </div>
	            </div>
	        </div>
	    </div>
	    <div class="modal fade" id="restPwdModal" tabindex="-1" role="dialog" style="display: none;">
	        <div class="modal-dialog modal-sm" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
	                    <h4 class="modal-title">温馨提示</h4>
	                    <input type="hidden" id="restPwdPhone" />
	                    <input type="hidden" id="restPwdUserID" />
	                </div>
	                <div class="modal-body">
	                    您确定要重置密码吗？重置后密码为手机号后六位数字！
	                </div>
	                <div class="modal-footer">
	                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
	                    <button type="button" class="btn btn-primary" id="restPassword">确定</button>
	                </div>
	            </div>
	        </div>
	    </div>
	    <div class="modal fade" id="addEmployeesModal" tabindex="-1" role="dialog" aria-labelledby="addEmployeesModalLabel">
	        <div class="modal-dialog" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
	                    <h4 class="modal-title text-base" id="addEmployeesModalLabel">编辑员工信息</h4>
	                </div>
	                <div class="modal-body">
	                    <h4 class="text-blue wrapper text-md font-bold m-t-none"></h4>
	                    <form class="form-horizontal" id="addEmployeeForm">
	                        <div class="form-group">
	                            <label for="recipient-name" class="control-label col-md-4"><span class="text-red">*</span> 姓　　名：</label>
	                            <div class="col-md-5 no-padder">
	                                <input type="text" class="form-control input-sm" name="userName" id="userName">
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4">性　　别：</label>
	                            <div class="col-md-5 no-padder">
	                                <label class="checkbox-inline">
	                                    <input type="radio" value="1" name="sex" id="sex1"><i></i>男
	                                </label>
	                                <label class="checkbox-inline">
	                                    <input type="radio" value="2" name="sex" id="sex2"><i></i>女
	                                </label>
	                                <label class="checkbox-inline">
	                                    <input type="radio" value="0" name="sex" checked="checked" id="sex3"><i></i>保密
	                                </label>
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4"><span class="text-red">*</span> 手机号码：</label>
	                            <div class="col-md-5 no-padder">
	                                <input type="text" class="form-control input-sm" name="phone" id="phone"  placeholder="输入您的电话号码" />
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4"><span class="text-red">*</span> 部　　门：</label>
	                            <div class="col-md-5 no-padder" style="position:relative">
	                              <select class="form-control input-sm no-shadow m-r-sm" name="departID" id="departID">
	                                  <option value="">请选择部门</option>
	                              </select>
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4"><span class="text-red">*</span> 职　　位：</label>
	                            <div class="col-md-5 no-padder">
	                                <input type="text" class="form-control input-sm" name="post" id="post" >
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4"> 邮　　箱：</label>
	                            <div class="col-md-5 no-padder">
	                                <input type="text" class="form-control input-sm" data-rule="email" name="email" id="email">
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4"> 部门领导：</label>
	                            <div class="col-md-5 no-padder">
	                              <label class="switch-container" style="margin-top: 7px;">
	                                <input type="checkbox" id="isLeader" name="isLeader" />
	                                <i></i>
	                              </label>
	                            </div>
	                        </div>
	                        <div class="form-group">
	                            <label for="message-text" class="control-label col-md-4" style="padding-top:0;"> 系统管理：</label>
	                            <div class="col-md-5 no-padder">
	                              <label class="switch-container">
	                                <input type="checkbox" id="isAdmin" name="isAdmin" />
	                                <i></i>
	                              </label>
	                            </div>
	                        </div>
	
	                        <div class="form-group">
	                            <div class="col-md-offset-4 col-md-5 no-padder m-t-sm m-b-sm">
	                                <input type="hidden" name="userID" id="userID">
	                                <button type="submit" class="btn btn-primary padder-md" id="addEmployeeBtn">保存</button>
	                                <button type="button" class="btn btn-default padder-md m-l-sm" data-dismiss="modal">取消</button>
	                            </div>
	                        </div>
	                    </form>
	                </div>
	            </div>
	        </div>
		</div>
		<div class="modal fade" id="defaultPwdTipsModal" tabindex="-1" role="dialog" style="display: none;">
	        <div class="modal-dialog modal-sm" role="document">
	            <div class="modal-content">
	                <div class="modal-header">
	                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
	                    <h4 class="modal-title">温馨提示</h4>
	                    <input type="hidden" id="restPwdPhone" />
	                    <input type="hidden" id="restPwdUserID" />
	                </div>
	                <div class="modal-body">
	                    该员工的默认密码为手机号后六位数字？
	                </div>
	                <div class="modal-footer">
	                    <button type="button" class="btn btn-default" data-dismiss="modal">知道了</button>
	                </div>
	            </div>
	        </div>
	    </div>
	</div>
	
	<script type="text/javascript" src="../../js/utils/jquery-1.12.4.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/bootstrap-treeview.js" ></script>
	<script type="text/javascript" src="../../js/utils/jquery.cookie.js" ></script>
	<script type="text/javascript" src="../../js/utils/jquery.validate.min.js?version=1" ></script>
	<script type="text/javascript" src="../../js/utils/page.js" ></script>
	<script type="text/javascript" src="../../js/utils/boot.js" ></script>
	<script type="text/javascript" src="../../js/utils/toastr.min.js" ></script>
	<script type="text/javascript" src="../../js/utils/depart.js" ></script>
	<script>
		var userID = $.cookie("userID");
		var companyID = $.cookie("companyID");
		var companyName = $.cookie("companyName");
		var isAdmin = $.cookie("isAdmin");
		var wechatID,wechatPayID,isActivate,departID,pageNo=1;
		$(function() {
			toastr.options = {
                "closeButton": true,
                "timeOut": 2000,
                "positionClass": "toast-center"
           	};
	   		departID = companyID;
			getEmployListData();
			getDepartListData();
		})
		function getDepartListData() {//获取部门数据
			base.postData(base.url.getDepartList, {userID:userID,companyID:companyID}, callbackGetDepartList);
		}
		//部门返回
		function callbackGetDepartList(data) {
			if (data.success) {
				$("#companyNameH4").text(data.context.companyName);
				var _parentList = data.context.parentList;
				getDeptsTree(_parentList);//把部分数据填充到树
				//把获取的部门树形结构数据转换成数组
				var _departList = getDepartList(_parentList);
				//获得部门下拉框对象
		        var departmentSt = document.getElementById("departID");
		        //遍历部门数据,并把部门的数据追加到option选项中
		        for (var i=0; i<_departList.length; i++) {
		            var option = document.createElement("option");
		            option.value = _departList[i].sectionID;
		            option.innerHTML = _departList[i].sectionName;
		            departmentSt.appendChild(option);
		        }
			}
		}
		function getDeptsTree(list) {
              $("#treeview").treeview({
                  data: JSON.stringify(list),
                  onNodeAdd: function(e, o) {
                      $("#parentDepartment").val(o.sectionName);
                      $("#parentDepartmentId").val(o.sectionID);
                      $("#department").val("");
                      $("#departmentId").val("");
                      $("#addDepartmentModalLabel").html("添加部门");
                      $('#addDepartmentModal').modal('show');
                  },
                  onNodeEdit: function(e, o) {

                      var p = $('#treeview').treeview('getParent', o);
                      var parentName = typeof(p.sectionName) === "undefined" ? companyName : p.sectionName;
                      $("#parentDepartment").val(parentName);
                      $("#department").val(o.sectionName);
                      $("#departmentId").val(o.sectionID);
                      $("#addDepartmentModalLabel").html("编辑部门");
                      $('#addDepartmentModal').modal('show');
                  },
                  onNodeRemove: function(e, o) {
                      $("#delDepartmentId").val(o.sectionID);
                      $("#delDepartmentName").html(o.sectionName);
                      $('#delDepartmentModal').modal('show');
                  },
                  onNodeSelected: function (e, o) {

                      var out = "<li class='active'>" + o.sectionName + "</li>";
                      var crumbs = "<li> aaa </li>" + getDeptCrumbs(o, out);
                      $("#breadcrumbs").html(crumbs);
                      $("#departmentId").val(o.sectionID);
                      $("#sDepartmentId").val(o.sectionID);
                      departID = o.sectionID;
                      getEmployListData();
                  }
              });
          };
          function getDeptCrumbs(deptId, out) {
              var p = $('#treeview').treeview('getParent', deptId);
              if(typeof(p.sectionID) === "undefined") {
                return out;
              } else {
                return getDeptCrumbs(p, "<li> " + p.sectionName + " </li>" + out);
              }
          }
        //获取员工列表
		function getEmployListData() {
			var data = {
				isActivate: isActivate,
				userName: $("#searchInput").val(),
				departID:departID,
				pageNo: pageNo,
				userID:userID,
				companyID:companyID
			}
			base.postData(base.url.getEmployList, data, callbackgetEmployList);
		}
		function callbackgetEmployList(data) {
			if (data.success) {
				if (pageNo == 1) {
					var _totalPage = Math.ceil(data.context.totalPage/10)||1;
					//初始化分页
					var page = {
						pageIndex:1,//初始页
						currentPage:1,//当前页
						showPage:5,//显示页数
						totalPage:_totalPage,//总页数
						onPageClick: function(page) {
							pageNo = page.currentPage;
							getEmployListData();
							$("#employeesPage").initPage(page);
			    			return false;  //默认的翻页事件
					    }
					};
				}
				$("#employeesPage").initPage(page);
				$("#employeestbody").html(getListHtml(data.context.dataList));
			}
		}
		function getListHtml (list) {
			var html = '';
			for (var index in list) {
				html += '<tr>'
				html += '	<td>'+(index*1+1)+'</td>'
				html += '	<td class="employees-name">'+list[index].username+'</td>'
				html += '	<td class="employees-phone">'+list[index].phone+'</td>'
				html += '	<td class="employees-post">'+list[index].post+'</td>'
				html += '	<td class="employees-email">'+list[index].email+'</td>'
				html += '	<td style="display: none;"><span class="employees-sectionId">'+list[index].sectionId+'</span><span class="employees-sex">'+list[index].sex+'</span><span class="employees-isLeader">'+list[index].isLeader+'</span><span class="employees-isAdmin">'+list[index].isAdmin+'</span></td>'
				html += '	<td>'+(list[index].isActivate?"已激活":"未激活")+'</td>'
				html += '	<td><button class="btn btn-default" data-type="1" data-employUserID = "'+list[index].id+'">修改</button><button class="btn btn-default" data-type="2" data-employUserID = "'+list[index].id+'">重置密码</button><button class="btn btn-default" data-type="3" data-employUserID = "'+list[index].id+'">删除</button></td>'
				html += '</tr>'
			}
			return html;
		}
		$("#addEmployeeForm").validate({
	       	rules:{
	       		userName: {required:true},
				phone:{isPhone: true},
				departID:{required:true},
				post:{required:true}
	       	},
	       	messages:{
	       		userName: {required: "请输入姓名"},
	          	phone:{required: "请填写正确的手机号码"},
	          	departID:{required: "请选择部门"},
	          	post:{required: "请输入职位"}
	       },
	       submitHandler: function() {
	       		var formSer = $("#addEmployeeForm").serialize().split("&");
              	var params = {};
              	for(var i=0;i<formSer.length; i++) {
                		var formItem = formSer[i].split("=");
              		params[formItem[0]] = decodeURIComponent(formItem[1]);
              	}
              	params.isAdmin = $("#isAdmin").prop("checked") ? 1:0;
              	params.isLeader = $("#isLeader").prop("checked") ? 1:0;
              	params["companyID"] = companyID;
              	console.log(params);
				base.postData(base.url.addUser, params, function(data) {
					if (data.success) {
						$("#addEmployeesModal").modal("hide");
						$("#defaultPwdTipsModal").modal("show");
						toastr.success(data.msg);
					} else {
						toastr.error(data.msg);
					}
				});
		    }
		})
		//删除员工
		$("#delEmployeesModal").on("click", "#delEmployBtn", function() {
			var _userID = $("#delEmployeesId").val();
			base.postData(base.url.delStaff, {companyID:companyID,userID:_userID},function(data) {
				if (data.success) {
					getEmployListData();//刷新数据
					$("#delEmployeesModal").modal("hide");
					toastr.success(data.msg);
				} else {
					toastr.error(data.msg);
				}
			});
		})
		//重置密码
		$("#restPwdModal").on("click", "#restPassword", function() {
			var _phone = $("#restPwdPhone").val();
			var _userID = $("#restPwdUserID").val();
			base.postData(base.url.edtStaffPassword, {companyID:companyID,phone:_phone,userID:_userID},function(data) {
				if (data.success) {
					$("#restPwdModal").modal("hide");
					toastr.success(data.msg);
				} else {
					toastr.error(data.msg);
				}
			});
		})
		//删除部门
		$("#delDepartmentModal").on("click", "#delDeptBtn", function() {
			var _departID = $("#delDepartmentId").val();
			base.postData(base.url.deleteSection, {departID:_departID}, function(data) {
				if (data.success) {
					getDepartListData();
					$('#delDepartmentModal').modal('hide');
					toastr.success(data.msg);
				} else {
					toastr.error(data.msg);
				}
			});
		})
		//添加修改部门
		$("#addDepartmentModal").on("click", "#saveDeptBtn", function() {
			var _departID = $("#departmentId").val();
			var _departName = $("#department").val();
			var _companyID = $("#parentDepartmentId").val();
			base.postData(base.url.addDepart, {departID:_departID,departName:_departName,companyID:_companyID}, function(data) {
				if (data.success) {
					getDepartListData();
					$('#addDepartmentModal').modal('hide');
					toastr.success(data.msg);
				} else {
					toastr.error(data.msg);
				}
			});
		})
		//点击公司搜索
		$("#companyNameH4").on("click", function(e) {
			departID = companyID;
			pageNo = 1;
			getEmployListData();
		})
		$(".add-tree-parent").on("click", function() {
			$("#parentDepartment").val(companyName);//上级部门 公司名称
			$("#parentDepartmentId").val(companyID);//上级部门 公司id
			$("#department").val("");
			$("#departmentId").val("");
			$("#addDepartmentModalLabel").html("添加部门");
			$('#addDepartmentModal').modal('show');
		})
		$("#addEmployees").on("click", function(e) {
			$("#addEmployeesModalLabel").html("添加员工信息");
            $("#userName").val("");
            $("#phone").val("");
            $("#post").val("");
            $("#userID").val("");
			$("#departID option:first").prop("selected", 'selected'); 
            $("#email").val("");
            $("#sex3").prop("checked", "checked");
            $("#isLeader").prop("checked", false);
            $("#isAdmin").prop("checked", false);
            $("#addEmployeesModal").modal("show");
        })
		//修改员工
		$("#employeestbody").on("click", "button", function() {
			var typeID = $(this).data('type');
			var _userID = $(this).attr('data-employUserID');//员工id
			var _phone = $(this).closest("tr").find(".employees-phone").text();
			var _userName = $(this).closest("tr").find(".employees-name").text();
			if (typeID == 1) { //1修改 2重置密码 3删除
				$("#addEmployeesModalLabel").html("编辑员工信息");
				$("#userName").val(_userName);
	            $("#phone").val(_phone);
	            $("#post").val($(this).closest("tr").find(".employees-post").text());
	            $("#userID").val($(this).attr("data-employUserID"));
	            $("#email").val($(this).closest("tr").find(".employees-email").text());
	            $("#sex"+$(this).closest("tr").find(".employees-sex").text()).prop("checked", "checked");
	            $("#isLeader").prop("checked", $(this).closest("tr").find(".employees-isLeader").text() == 1 ? true : false);
	            $("#isAdmin").prop("checked", $(this).closest("tr").find(".employees-isAdmin").text() == 1 ? true : false);
	            var sectionId = $(this).closest("tr").find(".employees-sectionId").text();
	            var departIDSelect = document.getElementById("departID");
				for (var i = 0; i < departIDSelect.options.length; i++){  
			        if (departIDSelect.options[i].value == sectionId){  
			            departIDSelect.options[i].selected = true;  
			            break;  
			        }  
			   	}
	            $("#addEmployeesModal").modal("show");
			} else if (typeID == 2) {
				$("#restPwdPhone").val(_phone);
				$("#restPwdUserID").val(_userID);
				$("#restPwdModal").modal("show");
			} else {
				$("#delEmployeesName").text(_userName);
				$("#delEmployeesId").val(_userID);
				$("#delEmployeesModal").modal("show");
			}
		})
		//搜索
		$('#searchInput').bind('keyup', function(event) {
			if (event.keyCode == "13") {
				console.log("进来了");
	　　　　		//回车执行查询
				$(this).blur();
				pageNo = 1;
				getEmployListData();
		　　	}
		});
		$("#activationSt").change(function() {
			isActivate = $(this).val();
			pageNo = 1;
			getEmployListData();
		})
	</script>
</body>
</html>
